﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Perform
{
    public partial class frmFlowerUpdate : Form
    {
        public frmFlowerUpdate()
        {
            InitializeComponent();
        }

        private void frmFlowerUpdate_Load(object sender, EventArgs e)
        {
            string sql = "select fname from flower";
            SqlDataReader sdr = Dal.DataHelper.ExecuteReader(sql);
            while (sdr.Read()) { cmbfname.Items.Add(sdr["fname"].ToString()); }
            string sql1 = string.Format("select iid from inventory");
            SqlDataReader sdr1 = Dal.DataHelper.ExecuteReader(sql1);
            while (sdr1.Read()) { cmbiid.Items.Add(sdr1["iid"].ToString()); }
        }

        private void btnupdate_Click(object sender, EventArgs e)
        {
            string sql1 = string.Format("update flower set fname='{0}',flauguage='{1}',fprimecost='{2}',fsalecost='{3}',iid='{4}' where fid='{5}'", cmbfname.Text.Trim(), tbflanguage.Text.Trim(), txtfprice.Text.Trim(), txtfsalecost.Text.Trim(), cmbiid.Text.Trim(), tbfid.Text.Trim());
            if (Dal.DataHelper.sqlExecuteNonQuery(sql1) > 0)
            {
                MessageBox.Show("修改鲜花信息成功！", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                MessageBox.Show("修改鲜花信息失败！", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }

        private void btnreset_Click(object sender, EventArgs e)
        {
            tbfid.Text = "";
            tbflanguage.Text = "";
            txtfprice.Text = "";
            txtfsalecost.Text = "";
            cmbfname.Text = "--请选择花名--";
        }

        private void cmbfname_SelectedIndexChanged(object sender, EventArgs e)
        {
            string sql = "select * from flower where fname='" + cmbfname.Text + "'";
            SqlDataReader sdr = Dal.DataHelper.ExecuteReader(sql);
            while (sdr.Read())
            {
                tbfid.Text = sdr["fid"].ToString();
                tbflanguage.Text = sdr["flauguage"].ToString();
                txtfprice.Text = sdr["fprimecost"].ToString();
                txtfsalecost.Text = sdr["fsalecost"].ToString();
                cmbiid.Text = sdr["iid"].ToString();
            }
        }
    }
}
